<?php
$username=$_COOKIE["username"];
$modifyPasswordCount=$_COOKIE[$username."modifyPasswordCount"];
?>
<!DOCTYPE html>
<html class="ui-page-login">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title>修改密码</title>
	<link rel="stylesheet" href="css/weui.css" type="text/css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/weui/0.4.3/style/weui.min.css" type="text/css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/jquery-weui/0.8.0/css/jquery-weui.min.css" type="text/css">
    <link rel="stylesheet" href="css/demos.css">
    <link href="css/mui.min.css" rel="stylesheet"/>
    <style>
        .hqyzm{
            position: absolute;
            right: 10px;
            top: 4px;
            background-color: #fb4746;
            color: #fff;
            border-radius: 30px;
            border: none;
        }
    </style>
</head>
<body>
    <header class="mui-bar mui-bar-nav">
        <h1 class="mui-title">剩余<?php echo $modifyPasswordCount;?>次重置密码机会</h1>
    </header>
    <div class="mui-content">
	
        <form class="mui-input-group">
		    <div class="mui-input-row">
                <label>原密码</label>
                <input id="oldpassword" type="password" class="mui-input-clear mui-input" placeholder="<?php if($modifyPasswordCount==0){ echo "无法输入";}else{ echo "请输入原密码";}?>" <?php if($modifyPasswordCount == 2){ echo "disabled";}?>/>
            </div>
            <div class="mui-input-row">
                <label>新密码</label>
                <input id="newpassword"  type="password" class="mui-input-clear mui-input" placeholder="<?php if($modifyPasswordCount==0){ echo "无法输入";}else{ echo "请输入新密码";}?>" <?php if($modifyPasswordCount == 2){ echo "disabled";}?>/>
            </div>
            <div class="mui-input-row">
                <label>确认密码</label>
                <input id="confirmnewpassword" type="password" class="mui-input-clear mui-input" placeholder="<?php if($modifyPasswordCount==0){ echo "无法输入";}else{ echo "请再次输入新密码";}?>" <?php if($modifyPasswordCount == 2){ echo "disabled";}?>/>
            </div>
        </form>
		
		<div class="mui-content-padded">
              <button class="mui-btn mui-btn-block mui-btn-danger border-radius" type="button" onclick="submit()">提 交</button>
        </div> 
		 
    </div>
	
	<script src="js/jquery-2.1.4.js"></script>
	<script src="js/fastclick.js"></script> 
	 
	<script src="http://cdn.bootcss.com/jquery-weui/0.8.0/js/jquery-weui.min.js"></script>
	
	<script>
	$(document)
	function getCookie(cname){
			var name = cname + "=";
			var ca = document.cookie.split(';');
			for(var i=0; i<ca.length; i++) {
			    var c = ca[i].trim();
				if (c.indexOf(name)==0) return c.substring(name.length,c.length);
			}
			return "";
	}
	
	
    function submit(){
            var oldpassword = $.trim($('#oldpassword').val());
			var newpassword = $.trim($('#newpassword').val());
			var confirmnewpassword = $.trim($('#confirmnewpassword').val());
			var password=getCookie("school[password]");
			
			if(oldpassword == ''){
				$.toptip('请输入原密码', 'warning');
				return;
			}else{
				if(oldpassword != password){
					 $.toptip('原密码输入错误', 'warning');
				     return;
				}
				
			}
			if(newpassword == ''){
				$.toptip('请输入新密码', 'warning');
				return;
			}
			if(confirmnewpassword == ''){
				$.toptip('请再次输入新密码', 'warning');
				return;
			}
			if(oldpassword == newpassword){
				$.toptip('新旧密码不能相同', 'warning');
				return;
			}
			if(newpassword != confirmnewpassword){
				$.toptip('新密码输入不一致', 'warning');
				return;
			}
			$.post("updatePassword.php",{'newpassword':newpassword},function(res){
				if(res.code == 0){
					$.toptip(res.msg, 'error');
				}else{
					$.toptip(res.msg, 'success');
					setTimeout(function(){window.location.href ="firstPage.php"},1000);
				}
			},'json');
        }
 </script>
</body>
</html>